//
//  WebsiteReviewsController.swift
//  AirTravel
//
//  Created by apple on 2021/7/22.
//

import UIKit

class WebsiteReviewsController: UIViewController {
    
    @IBOutlet weak var collView: UICollectionView!
    @IBOutlet weak var otherView: UIView!
    /// 其他
    @IBOutlet weak var otherBtn: UIButton!
    
    @IBOutlet weak var reviewView: UIView!
    /// 差评
    @IBOutlet weak var reviewBtn: UIButton!
    @IBOutlet weak var figureView: UIView!
    /// 有图
    @IBOutlet weak var figureBtn: UIButton!
    @IBOutlet weak var allView: UIView!
    @IBOutlet weak var allBtn: UIButton!
    
    @IBOutlet weak var allScoreLab: UILabel!
    @IBOutlet weak var scoreLab: UILabel!
    @IBOutlet weak var tabView: UITableView!
    let identifyTC = "TagColl"
    let identifyP = "Pure1Cell"
    let identifyECC = "EvaluationContentCell"
    
    lazy var evaluationViewModel: EvaluationImageViewModel = {
        let iconView = EvaluationImageViewModel()
        iconView.delegate = self
        return iconView
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.isNavigationBarHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "网友点评"
        self.collView.dataSource = self
        self.collView.delegate = self
        let layout = UICollectionViewFlowLayout.init()
        layout.scrollDirection = .vertical
        layout.itemSize = .init(width: (SCREEN_WIDTH - 36 - 24) / 3, height: 30)
        layout.minimumInteritemSpacing = 10
        layout.minimumLineSpacing = 12
        layout.sectionInset = UIEdgeInsets.init(top: 10, left: 18, bottom: 10, right: 18)
        self.collView?.collectionViewLayout = layout
        self.collView?.isScrollEnabled = false
        self.collView?.register(UINib.init(nibName: "TagColl", bundle: nil), forCellWithReuseIdentifier: identifyTC)
        
        self.tabView.dataSource = self
        self.tabView.delegate = self
        self.tabView.tableFooterView = UIView.init()
        self.tabView.register(UINib.init(nibName: "Pure1Cell", bundle: nil), forCellReuseIdentifier: identifyP)
        self.tabView.register(UINib.init(nibName: "EvaluationContentCell", bundle: nil), forCellReuseIdentifier: identifyECC)
    }


}

extension WebsiteReviewsController:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 6
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifyTC, for: indexPath) as! TagColl
        cell.contentLab.backgroundColor = UIColor(red: 252.0 / 255.0, green: 238.0 / 255.0, blue: 232.0 / 255.0, alpha: 1.0)
        cell.contentLab.text = "服务热情(221)"
        return cell
    }

}

extension WebsiteReviewsController:UITableViewDataSource,UITableViewDelegate{
    func numberOfSections(in tableView: UITableView) -> Int{
        return 6
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        switch indexPath.row {
        case 0:
            let cell = tableView.dequeueReusableCell(withIdentifier: identifyECC) as! EvaluationContentCell
            cell.selectionStyle = .none
            cell.separatorInset = UIEdgeInsets(top: 0, left: SCREEN_WIDTH, bottom: 0, right: 0)
            return cell
        default:
            let cell = tableView.dequeueReusableCell(withIdentifier: identifyP) as! Pure1Cell
            cell.selectionStyle = .none
            cell.separatorInset = UIEdgeInsets(top: 0, left: SCREEN_WIDTH, bottom: 0, right: 0)
            self.evaluationViewModel.bindViewToViewModel(collView: cell.collVIew)
            return cell
        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
        switch indexPath.row {
        case 1:
            return ((SCREEN_WIDTH - 42) / 3 + 6) * 2
        default:
            return UITableView.automaticDimension
        }
    }
}

extension WebsiteReviewsController:EvaluationDelegate{
    func evaluationClick(data: NSDictionary) {
        
    }
}
